﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Data;
using System.Data.SqlClient;
using Entity;

namespace Data
{

    public class FAQ_Data
    {
        SqlConnection con;
        SqlCommand comn;
        SqlDataAdapter da;
        DataSet ds;

        public bool Insert_FAQ(FAQ_Entity FAQ)
        {
            try
            {
                con = Connection.StartConnection();

                comn = new SqlCommand("FAQAdd", con);
                con.Open();
                comn.CommandType = CommandType.StoredProcedure;
                comn.Parameters.Add(new SqlParameter("@ques", FAQ.Ques));
                comn.Parameters.Add(new SqlParameter("@ans", FAQ.Ans));
                comn.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Connection.CloseConnection();
            }

            return true;
        }



        public int Update_FAQ(int faqID, string ques, string ans)
        {
            con = Connection.StartConnection();
            con.Open();
            comn = new SqlCommand("UpdateFAQ", con);
            comn.CommandType = CommandType.StoredProcedure;
            try
            {
                comn.Parameters.AddWithValue("@faqID", faqID);
                comn.Parameters.AddWithValue("@ques", ques);
                comn.Parameters.AddWithValue("@ans", ans);
                return comn.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                Connection.CloseConnection();
            }

        }
        public DataTable LoadP()
        {
            con = Connection.StartConnection();
            comn = new SqlCommand("BindFAQ", con);
            comn.CommandType = CommandType.StoredProcedure;
            da = new SqlDataAdapter(comn);

            ds = new DataSet();
            try
            {
                da.Fill(ds, "FAQ");
                return ds.Tables["FAQ"];
            }
            catch
            {
                throw;
            }
            finally
            {
                ds.Dispose();
                da.Dispose();
                con.Close();
                con.Dispose();
            }
        }

        public int Delete_FAQ(int faqID)
        {
            con = Connection.StartConnection();
            con.Open();
            comn = new SqlCommand("DeleteFAQ", con);
            comn.CommandType = CommandType.StoredProcedure;
            try
            {
                comn.Parameters.AddWithValue("@faqID", faqID);
                return comn.ExecuteNonQuery();
            }
            catch
            {
                throw;
            }
            finally
            {
                comn.Dispose();
                con.Close();
                con.Dispose();
            }
        }
    }
}
